/***
  * Author: Liveinlow, www.liveinlow.com.
  * Copyrights (c) 2012. Liveinlow.com
  * YOU CAN MODIFIED THIS CODE WHATEVER YOU WANT. ENJOY IT :-)
  *
***/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QCloseEvent>
#include <QtNetwork/QHttp>
#include <QIODevice>
#include <QTimer>
#include <QEvent>
#include <QCloseEvent>
#include <QSystemTrayIcon>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    
private:
    Ui::MainWindow *ui;

public:
    QString strBuffer; // For buffering data
    QString strData; // For saving words which Joejoejoe said.
    QHttp* http; // HTTP requester
    QTimer timer; // Timer to request
    QSystemTrayIcon* trayIcon;
    QMenu *trayIconMenu;
    QAction *showHideTray;
    QAction *closeTray;
    int requesID;

private:
    void displayDataToUi();

public slots:
    void requestFinished( int id, bool error );
    void readyRead ( const QHttpResponseHeader & resp );
    void done(bool error);
    void timeout(); // Timer's slot

protected:    
    virtual void closeEvent(QCloseEvent* event);
    virtual void changeEvent(QEvent* event);
private slots:
    void on_action_Save_as_triggered();

    void on_action_JoejoejoeReader_triggered();

    void on_actionHide_to_Tray_triggered();

    void on_action_Exit_triggered();

public slots:
    void showHideWindow();
    void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
    void setTrayIcon();
    void createTrayIcon();
    void createTrayActions();
};

#endif // MAINWINDOW_H
